<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <style>
      .hide {
        display: none;
      }
    </style>
  </head>
  <body>
    <div id="loadHtmlStr" class="loadHtmlStr hide"></div>
    <button onclick="printBtn()">批量打印</button>
    <script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
    <script>
      // 需要放在服务端 load()
      let htmlStr = "<html><head></head><body>";
      let footStr = "</body></html>";

      let batchPrint = new BatchPrint();

      function printBtn() {
        batchPrint.loadHtmlAndprint(20, "same", "template");
      }

      function BatchPrint() {
        this.loadHtmlAndprint = function(sameNum, printType, printHtmlName) {
          let _this = this;
          $("#loadHtmlStr").load(printHtmlName + ".html", function() {
            if (printType === "same") {
              _this.samePrint(sameNum);
            }
          });
        };

        this.samePrint = function(sameNum) {
          let printInnerHTML = "";
          for (let i = 0; i < sameNum; i++) {
            printInnerHTML += $("#loadHtmlStr")[0].innerHTML; //批量打印字符串
          }
          let printWindow = window.open("", "newwindow", "fullscreen=yes,location=no,menubar=no,status=no,titlebar=no,toolbar=no");
          printWindow.document.body.innerHTML = htmlStr + printInnerHTML + footStr; //添加内容
          printWindow.print();
          setTimeout(function() {
            printWindow.close();
          }, 1000);
        };
      }
    </script>
  </body>
</html>
